package com.jixiang.order.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.jixiang.common.constants.CodeMqConstants.*;

@Configuration
public class UpdateOrderMqConfig {
    /**
     * 声明交换机
     * @return Direct类型交换机
     */
    @Bean
    public DirectExchange updateOrderExchange(){
//        return ExchangeBuilder.directExchange(MQ_EXCHANGE_UPDATEORDER).delayed().build();
        return ExchangeBuilder
                .directExchange(MQ_EXCHANGE_UPDATEORDER) // 指定交换机类型和名称
                .delayed() // 设置delay的属性为true
//                .durable(true) // 持久化
                .build();
    }

    /**
     * 第1个队列
     */
    @Bean
    public Queue updateOrderQueue(){
        return new Queue(MQ_QUEUE_UPDATEORDER);
    }

    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding bindingQueue1WithUpdateOrder(Queue updateOrderQueue, DirectExchange updateOrderExchange){
        return BindingBuilder.bind(updateOrderQueue).to(updateOrderExchange).with(MQ_ROUTINGKEY_UPDATEORDER);
    }

}
